define(function (require,exports,module) {
    var myPub = require('./public');

    var mCancleParent = $('.js_allCancleParent');

    var shtml = '<h6 class="bulletH6">确认取消收藏吗？</h6>';

    // 禁止多次点击
    var delTapOff = true;
    // 弹框样式
    var layerStyle = 'background:rgba(0,0,0,.8);color:#fff;min-width:55%; border:0';

    mCancleParent.hammer().off('tap');
    mCancleParent.hammer().on('tap',function (e) {
        if(delTapOff){
            var _tag = e.gesture.target;
            var $target;

            _tag.nodeName.toLocaleLowerCase() == 'p' ? $target=$(_tag) : $target=$(_tag).parents('p');


            // 我的收藏中 取消收藏 (判断有没有那个元素，并且要类名是要匹配的)
            if($target.length > 0 && $target.hasClass('rightCancle') && $target.hasClass('js_cancleCollect')){
                //关闭一次
                delTapOff=false;
                //弹出询问层
                myPub.askLayer(shtml,function () {

                    var videoId = $target.attr('videoId');
                    G_JSON_GET('/video/collection?videoId=' + videoId+"&type=1",{},function(data){
                        if(data.status == 201){
                            //干掉最大的那个盒子，一整个的收藏
                            $target.parents('.js_myCollectionOne').remove();
                            if($('.js_myCollectionOne').length == 0){
                                $('.js_wrap').hide();
                                $('.js_errPage').show();
                                $('html').addClass("Height100");
                            }
                        }
                    });//数据库删除收藏
                    //删除掉后要关闭所有的弹层
                    myPub.LayerCloseAll();
                },function () {
                    myPub.LayerCloseAll();
                    return;
                },'no',function () {
                   // 成功弹出内容后要设置样式
                   // changeBulletStyle();
                    //弹层打开时，要设置回来
                    delTapOff = true;
                })
            }


            // 收藏操作
            if($target.length > 0  && $target.hasClass('js_collectBtn')){
                var videoId = $target.attr('videoId');
                //关闭一次
                delTapOff=false;
                //弹出询问层
                if($target.hasClass('active')) {
                    myPub.askLayer(shtml,function () {
                        G_JSON_GET('/video/collection?videoId=' + videoId+"&type=1",{},function(data){
                            if (data.status == 201){
                                $target.removeClass('active');
                            }
                            myPub.LayerCloseAll();
                        });//数据库删除收藏

                    },function () {
                        myPub.LayerCloseAll();
                    },'no',function () {
                        //弹层打开时，要设置回来
                        delTapOff=true;
                    })
                }
                else {
                    //数据库保存收藏
                    G_JSON_GET('/video/collection?videoId=' + videoId+"&type=0",{},function(data){
                        if (data.status == 200){
                            $target.addClass('active');
                            delTapOff=true;
                        }
                    });

                }

            }



            //  点赞+1
            if($target.length > 0 && $target.hasClass('js_getGreatNum')){
                var videoId = $target.attr('videoId');
                delTapOff=false;
                G_JSON_GET('/video/support?videoId=' + videoId,{},function(data){
                    if (data.status == 200 || data.status == 201){
                        // console.log($target.hasClass('numberAdded'));
                        if($target.hasClass('active')){
                            // console.log('aaa');
                            myPub.TipLayer_noShade('取消成功', layerStyle,function () {});
                            $target.find('.js_greatNum').html((parseInt($target.find('.js_greatNum').html())-1));
                            $target.removeClass('active');
                            delTapOff=true;
                            return;
                        }else{
                            $target.find('.js_greatNum').html((parseInt($target.find('.js_greatNum').html())+1));
                            $target.addClass('active');
                            delTapOff=true;
                        }
                    }
                });


            }
        }

    })

    //修改弹层默认样式
    function changeBulletStyle() {
        $('.layermbox .layermchild').css({"min-width":"60%"});

        $('.layermcont').css({"padding":"1.5rem 0.6rem 1.2rem"});

        $('.layermbtn').css({"border-top":"none","display":"flex","justify-content":"space-around","height":"2.5rem","line-height":"2.5rem"});

        $('.layermbtn').addClass('beforeNone');

        $('.layermbtn span').eq(0).attr("type",1);

        $('.layermbtn span').eq(1).attr("type",0);

        $('.layermbtn span[type="0"],.layermbtn span[type="1"]').css({"height":"2rem","line-height":"2rem","width":"40%","font-size":"0.82rem","letter-spacing":"2px","border-radius":"5px","background-color":"#D8D8D8","color":"#6C1E21" });
    }
})